namespace Csharp01._0930;

public class Demo
{
    public void TestPrint1()
    {
        Console.WriteLine("请输入三个整数（空格分开）：");
        string input = Console.ReadLine();
        string[] strs = input.Split(" ");
        int x = int.Parse(strs[0]);
        int y = int.Parse(strs[1]);
        int z = int.Parse(strs[2]);
       
        int[] numbers = { x, y, z };
        Array.Sort(numbers);
        
    
        Console.WriteLine("三个数由小到大排列为：{0} {1} {2}", numbers[0], numbers[1], numbers[2]);
    }
    public void TestPrint2()
    {
        int sum = 0;
        for (int i = 1; i <= 100; i++)
        {
            
            if (i % 7 != 0 && !i.ToString().Contains("7"))
            {
                Console.Write(i + " ");
                sum += i;
            }
        }
        Console.WriteLine("\n符合条件的数字总和为：" + sum);
    }
    public void TestPrint3()
    {
        for (int i = 1; i <= 9; i++)
        {
            for (int j = 1; j <= i; j++)
            {
                Console.Write($"{j}×{i}={i * j}\t");
            }
            Console.WriteLine();
        }
        
    }
    public void TestPrint4()
    { 
int count = 0;
        Console.WriteLine("1000以内的完数有：");
        for (int i = 1; i <= 1000; i++)
        {
            int sum = 0;//zhen因子之和
            
          
            for (int j = 1; j < i; j++)
            {
                if (i % j == 0)
                {
                    sum += j;
                }
            }
            
            if (sum == i)
            {
                Console.Write(i + " ");
                count++;
            }
        }
        Console.WriteLine();
        Console.WriteLine($"共有{count}个完数");
       
        
    }
    public void TestPrint5()
    {//键盘录入一个正整数，请求：1.它是几位数？2.逆序打印出各位数字。
    
        Console.WriteLine("请输入一个正整数：");
        
        string input = Console.ReadLine();
      
        if (!int.TryParse(input, out int number) || number <= 0)
        {
            Console.WriteLine("输入的数字格式有误或不是正整数！");
            return;
        }
        
        int temp = number;
        int length = 0;
        while (temp > 0)
        {
            length++;
            temp /= 10;
        }
        
        Console.WriteLine("该数位{0}位", length);
        for (int i = length - 1; i >= 0; i--)
        {
            char c = input[i];
            Console.Write(c + " ");
        }
        Console.WriteLine();
        
        
    }
    public void TestPrint6()
    {
        Console.WriteLine("请输入菱形的行数（奇数）：");
        string input = Console.ReadLine();
        
        if (!int.TryParse(input, out int rows) || rows <= 0 || rows % 2 == 0)
        {
            Console.WriteLine("输入的行数必须是正奇数！");
            return;
        }
        int mid = rows / 2; 
        
        for (int i = 0; i <= mid; i++)
        {
            for (int j = 0; j < mid - i; j++)
            {
                Console.Write(" ");
            }
            for (int k = 0; k < 2 * i + 1; k++)
            {
                Console.Write("*");
            }
            Console.WriteLine();
        }
        
        for (int i = mid - 1; i >= 0; i--)
        {
           
            for (int j = 0; j < mid - i; j++)
            {
                Console.Write(" ");
            }
            for (int k = 0; k < 2 * i + 1; k++)
            {
                Console.Write("*");
            }
            Console.WriteLine();
        }
    }
}